<template>
	<view class="contract-edit">
		<cu-custom bgColor="bg-gradual-blue" :isBack="true" backIcon="cuIcon-close">
			<block slot="backText">关闭</block>
			<block slot="content">合同网签</block>
		</cu-custom>
		<form v-if="!loadProgress">
			<view class="cu-bar bg-white solid-bottom  margin-top">
				<view class="action">
					<text class="cuIcon-title text-blue"></text>合同信息
				</view>
			</view>
			<view class="cu-form-group">
				<view class="title">合同编号:</view>
				<input  name="input" v-model="contract.num" :disabled="disabled"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">交易金额:</view>
				<input placeholder="请输入交易金额,单位(元)" name="input" v-model="contract.money" :disabled="disabled"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">移交日期:</view>
				<input type="text" v-model="contract.date" :disabled="disabled"></input>
				<!-- <picker mode="contract.date" :value="contract.date"  @change="DateChange">					
				<view class="picker">
						{{}}
					</view>
				</picker> -->
			</view>
			
			
			<view class="cu-bar bg-white solid-bottom  margin-top">
				<view class="action">
					<text class="cuIcon-title text-blue"></text>房屋信息
				</view>
			</view>
			
	
			<view class="cu-form-group">
				<view class="title">权利人身份证号</view>
				<input placeholder="" v-model="house.obligeeIdentityNum" :disabled="disabled"></input>
			</view>	
			<view class="cu-form-group">
				<view class="title">建筑面积</view>
				<input placeholder="平方米" name="input" v-model="hous.buildArea" :disabled="disabled"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">套内建筑面积</view>
				<input placeholder="平方米" name="input" v-model="house.insideBuildArea" :disabled="disabled"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">房屋坐落</view>
				<input placeholder="请输入房屋坐落的详细地址,省市区不用填写" name="input" v-model="house.location" :disabled="disabled"></input>
			</view>	
			
			<view class="margin-top cu-form-group">
				<view class="title">合同所在目录</view>
				<input  v-model="dir" :disabled="disabled"></input>
			</view>
			
			<view class="cu-bar bg-white margin-top">
				<view class="action">
					合同签字页
				</view>
				<view class="action">
					{{imgList.length}}/4
				</view>
			</view>
			<view class="cu-form-group">
				<view class="grid col-4 grid-square flex-sub">
					<view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage($event, 'imgList')" :data-url="imgList[index]">
					 <image :src="imgList[index]" mode="aspectFill"></image>
						<view class="cu-tag bg-red" @tap.stop="DelImg($event, 'imgList')" :data-index="index">
							<text class='cuIcon-close'></text>
						</view>
					</view>
					<view class="solids" @tap="ChooseImage('imgList')" v-if="imgList.length<4">
						<text class='cuIcon-cameraadd'></text>
					</view>
				</view>
			</view>
			
			<view class="cu-bar bg-white margin-top">
				<view class="action">
					合同信息及其他要件
				</view>
				<view class="action">
					{{otherImgList.length}}/4
				</view>
			</view>
			<view class="cu-form-group">
				<view class="grid col-4 grid-square flex-sub">
					<view class="bg-img" v-for="(item,index) in otherImgList" :key="index" @tap="ViewImage($event, 'otherImgList')" :data-url="otherImgList[index]">
					 <image :src="imgList[index]" mode="aspectFill"></image>
						<view class="cu-tag bg-red" @tap.stop="DelImg($event, 'otherImgList')" :data-index="index">
							<text class='cuIcon-close'></text>
						</view>
					</view>
					<view class="solids" @tap="ChooseImage('otherImgList')" v-if="otherImgList.length<4">
						<text class='cuIcon-cameraadd'></text>
					</view>
				</view>
			</view>
			
		</form>
		
		
		
		<view class="padding" v-if="!loadProgress">
			<button class="cu-btn block bg-blue margin-tb-sm lg"  @click="submitSign">
				提交网签</button>
		</view>
		<view class="load-progress" :class="loadProgress!=0?'show':'hide'" :style="[{top:CustomBar+'px'}]">
			<view class="load-progress-bar bg-cyan" :style="[{transform: 'translate3d(-' + (100-loadProgress) + '%, 0px, 0px)'}]"></view>
			<view class="load-progress-spinner text-cyan"></view>
		</view>
	</view>
</template>

<script>
	let _this = null;
	export default {
		data() {
			let currentDate = this.getDate({
				format: true
			})
			return {
				CustomBar: this.CustomBar,
				disabled: true,
				region: ['贵州省', '贵阳市', '南明区'],
				dir: 'F:\\ContractFile',
				contract: {
					num: '566446',
					money: '356642',
					date: '2016-9-6'
				},
				location: '',
				imgList: [],
				otherImgList: [],
				loadProgress: 0,
				house: {
					obligeeIdentityNum: '522122197584657',
					qzNum: '423',
					location: '贵州省贵阳市南明区花果园C区二栋3单元4-01',
					buildArea: '168',
					insideBuildArea: '158',
				}
			}
		},
		onLoad (route) {
			
		},
		
		created () {
			_this = this;
		},
		mounted () {
			this.LoadProgress()
		},
		methods: {
			submitSign () {
				uni.showToast({
					title: "正在开发中",
					icon: 'none'
				})
			},
			DateChange(e) {
				_this.contract.date = e.detail.value
			},
			contractGenerate () {
				uni.navigateTo({
					url: '/pages/contract-sign/contract-sign'
				})
			},
			RegionChange(e) {
				_this.region = e.detail.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
			
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			ChooseImage(str) {
				uni.chooseImage({
					count: 4, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						// if (_this.imgList.length != 0) {
						// 	_this.imgList = _this.imgList.concat(res.tempFilePaths)
						// } else {
						// 	_this.imgList = res.tempFilePaths
						// }
						if (_this[str].length != 0) {
							_this[str] = _this[str].concat(res.tempFilePaths)
						} else {
							_this[str] = res.tempFilePaths
						}
					}
				});
			},
			ViewImage(e, str) {
				uni.previewImage({
					urls: _this[str],
					current: e.currentTarget.dataset.url
				});
			},
			DelImg(e, str) {
				uni.showModal({
					title: '提示',
					content: '确定要删除？',
					cancelText: '再看看',
					confirmText: '再见',
					success: res => {
						if (res.confirm) {
							_this[str].splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			LoadProgress(e) {
				this.loadProgress = this.loadProgress + 3;
				if (this.loadProgress < 100) {
					setTimeout(() => {
						this.LoadProgress();
					}, 100)
				} else {
					this.loadProgress = 0;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}

</style>
